﻿/*
 * RelationKeeper
 * 
 * initial implementation : 20.7.2011
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Collections.Generic;

namespace Petra.Gis.RenderingServices.PlanarBase.Support
{

  /// <summary>
  /// KeepRelationWith handles inheritance problem where 2 different child objects types
  /// need keep reference to single (same type) parent item.
  /// For example, data legend node and child nodes collection of leaf node
  /// needs keep reference to parent leaf legend node.
  /// Relation to parent here remains hidden.
  /// </summary>
  public abstract class KeepRelationWith<partnerType>
  {

    private Dictionary<string, object> _registeredProperties;

    /// <summary>
    /// keeps private relation between 2 classes
    /// </summary>
    protected partnerType __parent
    { get; set; }




    protected static void __registerProperty(KeepRelationWith<partnerType> item, string propertyName)
    {
      if (item._registeredProperties == null)
        item._registeredProperties = new Dictionary<string, object>();

      item._registeredProperties.Add(propertyName, null);
    }




    protected static object __getPropetyValue(KeepRelationWith<partnerType> item, string propertyName)
    {
      return item._registeredProperties[propertyName];
    }




    protected static void __setPropetyValue(KeepRelationWith<partnerType> item, string propertyName, object value)
    {
      item._registeredProperties[propertyName] = value;
    }




    /// <summary>
    /// create partnership where child saves reference to parent
    /// </summary>
    /// <param name="parent">parent/master object</param>
    /// <param name="child">child/slave object that saves relation to parent/master</param>
    protected static void __setParent(partnerType parent, KeepRelationWith<partnerType> child)
    {
      child.__parent = parent;
    }



  }

}
